package com.dpj.n7;

import lombok.extern.slf4j.Slf4j;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;

@Slf4j(topic = "c.Test1")
public class Test1 {
    public static void main(String[] args) {
         //   test1();

        DateTimeFormatter stf=DateTimeFormatter.ofPattern("yyyy-MM-dd");
        for (int i = 0; i <10 ; i++) {
            new Thread(()->{
                //jdk8新引入的日期对象
                TemporalAccessor parse = stf.parse("1951-04-21");
                log.debug("{}",parse);
            }).start();
        }
    }
    private static void test1(){


        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        for (int i = 0; i < 10; i++) {
            new Thread(()->{
                //多线程下访问 sdf 会出现错误，可以通过加锁的方式解决
               synchronized (sdf){
                   try {
                       log.debug("{}",sdf.parse("1999-04-06"));
                   } catch (ParseException e) {
                       log.debug("{}",e);
                   }
               }

            }).start();
        }
    }
}
